/**
 * 配送范围管理初始化
 */
var DeliveryRange = {
    id: "DeliveryRangeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DeliveryRange.initColumn = function () {
    return [
            {type: 'checkbox', fixed: 'left'},
            {title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '网点名称', field: 'dotName', visible: true, align: 'center', valign: 'middle'},
           //{title: '部门ID', field: 'detpId', visible: false, align: 'center', valign: 'middle'},
          //{title: '开始时间', field: 'startTime', visible: true, align: 'center', valign: 'middle'},
        //   {title: '结束时间', field: 'endTime', visible: true, align: 'center', valign: 'middle'},
        //  {title: '交货方式 0 自提 1配送', field: 'goodsMode', visible: true, align: 'center', valign: 'middle'},
            {title: '省份', field: 'proPlaceName', visible: true, align: 'center', valign: 'middle'},
            {title: '城市', field: 'cityPlaceName', visible: true, align: 'center', valign: 'middle'},
            {title: '区/县', field: 'regPlaceName', visible: true, align: 'center', valign: 'middle'},
            {title: '使用状态', field: 'isUse', visible: true, align: 'center', valign: 'middle'},//0是 1否
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
            //{title: '更新时间', field: 'updateTime', visible: true, align: 'center', valign: 'middle'},
          //
    ];
};

/**
 * 检查是否选中
 */
DeliveryRange.check = function () {

    var selected = mTable.checkStatus(DeliveryRange.id);
    // var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.data.length == 0 || selected.data.length > 1) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        DeliveryRange.seItem = selected.data[0];
        return true;
    }
};

/**
 * 点击添加配送范围
 */
DeliveryRange.openAddDeliveryRange = function () {
    var index = layer.open({
        type: 2,
        shade: 0.01,
        title: '添加配送范围',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/deliveryRange/deliveryRange_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看配送范围详情
 */
DeliveryRange.openDeliveryRangeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            shade: 0.01,
            title: '配送范围详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/deliveryRange/deliveryRange_update/' + DeliveryRange.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 删除配送范围
 */
DeliveryRange.delete = function () {
    if (this.check()) {
        var operation = function(){
            var deliveryRangeId = DeliveryRange.seItem.id;
            var ajax = new $ax(Feng.ctxPath + "/deliveryRange/delete", function (data) {
                if(data.code==200){
                    Feng.success("添加成功!");
                    aTable.refresh();
                }else{
                    Feng.success(data.message + "!");
                }
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("deliveryRangeId", deliveryRangeId);
            ajax.start();
        };
        Feng.confirm("是否删除配送范围?",operation);

    }
};

/**
 * 查询配送范围列表
 */
DeliveryRange.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    aTable.refresh(queryData);
};

var aTable = null
var mTable = null;
$(function () {
    var defaultColunms = DeliveryRange.initColumn();
    aTable = new LYTable(DeliveryRange.id,  "/deliveryRange/list", defaultColunms);
    // table.setPaginationType("client");
    layui.use('table', function () {
        mTable = layui.table;
        DeliveryRange.table = aTable.init(mTable);
    })

});